clear
import excel "~Appendix\clinton_supplemental_anonymous.xlsx", sheet("Dissertation+Plan+B_October+4%2") firstrow

foreach var of varlist d1-d7 c1-c7 t1-t7{
	gen `var'2 = .
	replace `var'2 = 0 if `var' == "Strongly agree"
	replace `var'2 = 0 if `var' == "Strongly Agree"
	replace `var'2 = 1 if `var' == "Agree"
	replace `var'2 = 2 if `var' == "Neither agree nor disagree"
	replace `var'2 = 2 if `var' == "Neither Agree nor disagree"
	replace `var'2 = 3 if `var' == "Disagree"
	replace `var'2 = 4 if `var' == "Strongly disagree"
	replace `var'2 = 4 if `var' == "Strongly Disagree"
}
*
** alpha should = 0.8908
alpha d12-d72
factor d12-d72, ipf factor(1)
rotate, promax
predict preLegit

alpha c12-c72
factor c12-c72, ipf factor(1)
rotate, promax
predict postControl

alpha t12-t72
factor t12-t72, ipf factor(1)
rotate, promax
predict postTreatment

gen controlLegit = postControl - preLegit 
gen treatLegit = postTreatment - preLegit 
egen diffLegit = rowmean(controlLegit treatLegit)


gen treatmentDum = .
replace treatmentDum = 0 if postControl != .
replace treatmentDum = 1 if postTreatment != .

label define treatmentDum 0 "Control" 1 "Treated"
label values treatmentDum treatmentDum

** coded such that high values indicate belief that SC is more politicized
foreach var of varlist p1-p3{
	gen `var'2 = .
	replace `var'2 = 4 if `var' == "Strongly Agree"
	replace `var'2 = 3 if `var' == "Agree"
	replace `var'2 = 2 if `var' == "Neither Agree nor Disagree"
	replace `var'2 = 1 if `var' == "Disagree"
	replace `var'2 = 0 if `var' == "Strongly Disagree"
}
*
alpha p12-p32
factor p12-p32, ipf factor(1)
rotate, promax
predict politicization


gen approval = . 
replace approval = 0 if sc_approval == "Disapprove"
replace approval = 1 if sc_approval == "Approve"

** support for minority liberty coded such that high values mean more tolerance
foreach var of varlist tol1-tol3{
	gen `var'2 = .
	replace `var'2 = 0 if `var' == "Strongly agree"
	replace `var'2 = 1 if `var' == "Somewhat agree"
	replace `var'2 = 2 if `var' == "Neither agree nor disagree"
	replace `var'2 = 3 if `var' == "Somewhat disagree"
	replace `var'2 = 4 if `var' == "Strongly disagree"
}
*
alpha tol12-tol32
factor tol12-tol32, ipf factor(1)
rotate, promax
predict minority_liberty


** respect for rule of law coded such that high values mean more respect
foreach var of varlist law1-law5{
	gen `var'2 = .
	replace `var'2 = 0 if `var' == "Strongly agree"
	replace `var'2 = 1 if `var' == "Agree"
	replace `var'2 = 2 if `var' == "Neither agree nor disagree"
	replace `var'2 = 3 if `var' == "Disagree"
	replace `var'2 = 4 if `var' == "Strongly disagree"
}
*
alpha law12-law52
factor law12-law52, ipf factor(1)
rotate, promax
predict ruleOfLaw


foreach var of varlist news_paper-news_vox{
	gen `var'2 = .
	replace `var'2 = 0 if `var' == "Less than once a month"
	replace `var'2 = 1 if `var' == "Once a month"
	replace `var'2 = 2 if `var' == "A few times a month"
	replace `var'2 = 3 if `var' == "Once a week"
	replace `var'2 = 4 if `var' == "A few times a week"
	replace `var'2 = 4 if `var' == "Every day"
}
*

gen diffMeda = ((news_cable2 + news_radio2) - (news_paper2 + news_network2))



foreach var of varlist scideo1 scideo2{
	gen `var'2 = .
	replace `var'2 = 1 if `var' == "Very liberal"
	replace `var'2 = 2 if `var' == "Somewhat liberal"
	replace `var'2 = 3 if `var' == "Moderate"
	replace `var'2 = 4 if `var' == "Somewhat conservative"
	replace `var'2 = 5 if `var' == "Very conservative"
}
*

gen ideology = .
replace ideology = 1 if self == "Extremely liberal"
replace ideology = 2 if self == "Liberal"
replace ideology = 2 if self == "Slightly liberal"
replace ideology = 3 if self == "Moderate"
replace ideology = 4 if self == "Slightly conservative"
replace ideology = 4 if self == "Conservative"
replace ideology = 5 if self == "Extremely conservative"


gen preIdeoDiff = 0
replace preIdeoDiff = 1 if scideo12 ==1 & ideology ==2 
replace preIdeoDiff = 1 if scideo12 ==2 & ideology ==1 
replace preIdeoDiff = 1 if scideo12 ==2 & ideology ==3 
replace preIdeoDiff = 1 if scideo12 ==3 & ideology ==2 
replace preIdeoDiff = 1 if scideo12 ==3 & ideology ==4 
replace preIdeoDiff = 1 if scideo12 ==4 & ideology ==3 
replace preIdeoDiff = 1 if scideo12 ==4 & ideology ==5 
replace preIdeoDiff = 1 if scideo12 ==5 & ideology ==4 

replace preIdeoDiff = 2 if scideo12 ==1 & ideology ==3 
replace preIdeoDiff = 2 if scideo12 ==2 & ideology ==4 
replace preIdeoDiff = 2 if scideo12 ==3 & ideology == 1
replace preIdeoDiff = 2 if scideo12 ==3 & ideology == 5
replace preIdeoDiff = 2 if scideo12 ==4 & ideology ==2 
replace preIdeoDiff = 2 if scideo12 ==5 & ideology ==3

replace preIdeoDiff = 3 if scideo12 ==1 & ideology ==4 
replace preIdeoDiff = 3 if scideo12 ==2 & ideology ==5 
replace preIdeoDiff = 3 if scideo12 ==4 & ideology ==1 
replace preIdeoDiff = 3 if scideo12 ==5 & ideology ==2

replace preIdeoDiff = 4 if scideo12 == 1& ideology ==5 
replace preIdeoDiff = 4 if scideo12 ==5 & ideology == 1  




gen postIdeoDiff = 0
replace postIdeoDiff = 1 if scideo22 ==1 & ideology ==2 
replace postIdeoDiff = 1 if scideo22 ==2 & ideology ==1 
replace postIdeoDiff = 1 if scideo22 ==2 & ideology ==3 
replace postIdeoDiff = 1 if scideo22 ==3 & ideology ==2 
replace postIdeoDiff = 1 if scideo22 ==3 & ideology ==4 
replace postIdeoDiff = 1 if scideo22 ==4 & ideology ==3 
replace postIdeoDiff = 1 if scideo22 ==4 & ideology ==5 
replace postIdeoDiff = 1 if scideo22 ==5 & ideology ==4 

replace postIdeoDiff = 2 if scideo22 ==1 & ideology ==3 
replace postIdeoDiff = 2 if scideo22 ==2 & ideology ==4 
replace postIdeoDiff = 2 if scideo22 ==3 & ideology == 1
replace postIdeoDiff = 2 if scideo22 ==3 & ideology == 5
replace postIdeoDiff = 2 if scideo22 ==4 & ideology ==2 
replace postIdeoDiff = 2 if scideo22 ==5 & ideology ==3

replace postIdeoDiff = 3 if scideo22 ==1 & ideology ==4 
replace postIdeoDiff = 3 if scideo22 ==2 & ideology ==5 
replace postIdeoDiff = 3 if scideo22 ==4 & ideology ==1 
replace postIdeoDiff = 3 if scideo22 ==5 & ideology ==2

replace postIdeoDiff = 4 if scideo22 == 1& ideology ==5 
replace postIdeoDiff = 4 if scideo22 ==5 & ideology == 1  

*** coded such that larger values indicate
*** that the difference has grown, and 
*** smaller values indicate the distance between
*** oneself and the perceived position of the Court
*** has shrunk
gen ideoDiff = postIdeoDiff - preIdeoDiff


rename pid partyid
gen pid = .
replace pid = 1 if partyid == "Democrat" & strong_d == "Strong"
replace pid = 2 if partyid == "Democrat" & strong_d == "Not very strong"
replace pid = 3 if partyid == "Independent" & leaner == "Democratic Party"
replace pid = 4 if partyid == "Independent" & leaner == "Neither"
replace pid = 4 if partyid == "Other" & leaner == "Neither"
replace pid = 5 if partyid == "Independent" & leaner == "Republican party"
replace pid = 6 if partyid == "Republican" & strong_r == "Not very strong"
replace pid = 7 if partyid == "Republican" & strong_r == "Strong"

gen female = .
replace female = 0 if gender == "Male"
replace female = 1 if gender == "Female"

drop if age == 225

gen eduCat = .
replace eduC = 0 if educat == "Did not graduate high school"
replace eduC = 1 if educat == "High school diploma or equivalent (GED)"
replace eduC = 2 if educat == "Some college but no degree"
replace eduC = 3 if educat == "Bachelor's degree (BA, MS, BSW, etc.)"
replace eduC = 4 if educat == "Graduate degree (MA, MS, MSW, MD, PhD, etc.)"



gen incomeCat = .
replace incomeC = 0 if income == "Less than $10,000"
replace incomeC = 0 if income == "$10,000 - $19,999"
replace incomeC = 0 if income == "$20,000 - $29,999" 
replace incomeC = 0 if income == "$30,000 - $39,999" 
replace incomeC = 0 if income == "$40,000 - $49,999" 
replace incomeC = 0 if income == "$50,000 - $59,999" 
replace incomeC = 0 if income == "$60,000 - $69,999" 
replace incomeC = 0 if income == "$70,000 - $79,999" 
replace incomeC = 0 if income == "$80,000 - $89,999" 
replace incomeC = 0 if income == "$90,000 - $99,999" 
replace incomeC = 0 if income == "$100,000 - $149,999" 
replace incomeC = 0 if income == "More than $150,000" 


egen min = min(diffM)
egen max = max(diffM)
replace diffM = ((diffM - min)/(max - min))
drop min max
egen min = min(politic)
egen max = max(politic)
replace politic = ((politic - min)/(max - min))
drop min max
egen min = min(minority)
egen max = max(minority)
replace minority = ((minority - min)/(max - min))
drop min max
egen min = min(rule)
egen max = max(rule)
replace rule = ((rule - min)/(max-min))
drop min max



*** randomization check
sort treatment
by treatment: sum age
by treatment: sum female
by treatment: sum eduC
by treatment: sum diffM
by treatment: sum clinton
by treatment: sum scotus
by treatment: sum preIdeo
by treatment: sum approval
by treatment: sum ideology
by treatment: sum pid
by treatment: sum politic
by treatment: sum minority
by treatment: sum rule


*** change in legitimamcy regression no controls
reg diffLegit c.clinton##i.treatment


***malleability regression with controls
reg diffLegit c.clinton##i.treatment polit approval scotus minority rule ///
	preIdeoDiff diffMe pid female age eduC i.treatment, beta



*** updating or balancing regression with controls
reg treatLegit clinton ideoDiff politic approval ///
	scotus minority rule diffM pid female age eduC incomeC, beta
